from configs import app_config
from flask import request,g,has_request_context
from agent_app import AgentApp
from flask_babel import Babel,gettext
import time
LANGUAGES =["en", "zh"]
def get_locale():
    request.headers.get("Accept-Language")
    language = request.accept_languages.best_match(LANGUAGES)
    if not language:
        return "zh"
    return language

def get_timezone():
    if has_request_context():
        if "_login_user" in g:
            timezone = getattr(g._login_user,'timezone',None)
            if timezone:
                return timezone 
    return time.timezone
        
def is_enabled()->bool:
    return True
def init_app(app: AgentApp):
    
    # babel.init_app(app,)
    app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans'
    app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'locals'
    # app.config['BABEL_DOMAIN'] = 'messages'
    babel = Babel(app,locale_selector=get_locale,timezone_selector=get_timezone)
    print(gettext("Account already in tenant."))
